<template>
 <div>
   <h1>汽车品牌</h1>
   <div>
  <el-button type="primary" @click="addcar">添加汽车品牌</el-button>
</div>
   <el-table
    :data="carbrandlist"
    style="width: 100%">
    <el-table-column
      label="编号"
      prop="num"
      width="180">
      
    </el-table-column>
    <el-table-column
      label="汽车品牌"
       prop="date"
      width="180">
      
    </el-table-column>
    
    <el-table-column label="操作">
      <template slot-scope="scope">
        <el-button
          size="mini"
          @click="handleEdit(scope.row)">修改</el-button>
      </template>
    </el-table-column>
  </el-table>
  <el-pagination
        background
        layout="total,prev, pager, next"
        :total="totalCount"
        :page-size="size"
        @current-change="currentChange"
      >
      </el-pagination>
  </div>
</template>

<script>
  export default {
    created() {
    // 获取订单源
    this.getInit();
    // 
  },
    data() {
      return {
        carbrandlist:[],
        initbrandlist:[],
        totalCount: 0,
        page:1,
        size:4,
      }
    },
    methods: {

      currentChange(page) {
      console.log(this.size);
      console.log("分页", page);
      this.page = page;
      this.carbrandlist=this.initbrandlist.slice(this.size*page-this.size,this.size*page)

      // this.getInit(page, this.size);
    },
      //传值
      handleEdit(form) {
        //console.log('bianji',form)
        this.$router.push({name:"xiugaiCarBreand", params: {key: form}});
      },
      handleDelete(index, row) {
        console.log(index, row);
      },
      addcar() {
        this.$router.push("/content/carbrand/add");
      },
      getInit(){
        this.$http({
        url: "/automobileBrand/selectAll",
        method: "POST",
        params: {
          
          }
      })
      .then((res) => {
         res.data.data.forEach((i,index) => {
             this.initbrandlist.push({
              num:index+1,
              date:i
             })
          })

         this.totalCount=this.initbrandlist.length 
         this.currentChange(1)
      })
      .catch((err) => {
          console.log('订单来源数据获取失败', err)
          
        })
      }
      
    }
  }
</script>
